package com.vhuomai.product.home.service.impl;

import com.quanyue.auto.util.GlobalContext;
import com.vhuomai.product.home.dto.HomeEntranceResult;
import com.vhuomai.product.home.entity.BaseHomeEntrance;
import com.vhuomai.product.home.mapper.HomeEntranceMapper;
import com.vhuomai.product.home.service.HomeEntranceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class HomeEntranceServiceImpl implements HomeEntranceService {
    @Autowired
    private HomeEntranceMapper homeEntranceMapper;

    @Override
    public void createHomeEntrance(BaseHomeEntrance homeEntrance) {
        homeEntrance.setId(null);
        homeEntrance.setMerchantNo(GlobalContext.merchantNo());
        homeEntrance.setCreateTime(LocalDateTime.now());
        homeEntrance.setUpdateTime(LocalDateTime.now());
        homeEntranceMapper.insert(homeEntrance);
    }

    @Override
    public void updateHomeEntrance(BaseHomeEntrance homeEntrance) {
        homeEntrance.setUpdateTime(LocalDateTime.now());
        homeEntranceMapper.updateSelective(homeEntrance);
    }

    @Override
    public void deleteHomeEntrance(Integer id) {
        homeEntranceMapper.deleteOne(id);
    }

    @Override
    public List <HomeEntranceResult> homeEntranceList() {
        return homeEntranceMapper.findByMerchantNo(GlobalContext.merchantNo());
    }
}
